home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / demo Source ƒ / demoTab.c < prev    next >
Encoding:
Text File  |  1995-10-27  |  2.7 KB  |  119 lines  |  [TEXT/KAHL]

  1. // -----------------------------------------------------------------------------
  2. //    File        : demoTab.c
  3. //    Date        : November 5, 1994
  4. //    Author        : Jim Stout
  5. //    Purpose        : some tabPanel demonstrations
  6. //
  7. // -----------------------------------------------------------------------------
  8. #include <GestaltEqu.h>
  9.  
  10. #include "demoShell.h"
  11. #include "demoTab.h"
  12. #include "dialogAssist.h"
  13. #include "movableModal.h"
  14. #include "panelAssist.h"
  15.  
  16. #define TABCNTL        3        // ID for Tab control
  17. #define CTLTOKEEP    4        // controls that are on all panels
  18.  
  19. #define FIRSTPANEL    160        // DITL id for "base" panel
  20.  
  21. #define DEMOTAB1    160        // DLOG id's for each demo
  22. #define DEMOTAB2    180
  23. #define DEMOTAB3    190
  24. #define DEMOTAB4    200
  25.  
  26. static pascal char    tabFilter    (DialogPtr theDialog, EventRecord *theEvent, 
  27.                                         short *theItem);
  28.  
  29. extern void demoTab(short demoNum)
  30. {
  31.     DialogPtr        d;
  32.     ModalFilterUPP    filterUPP;
  33.     short            currPanel=1,toPanel,itemHit;
  34.     GrafPtr            savePort;
  35.     
  36.     if(daGestalt(gestaltDITLExtAttr) == -1L) {
  37.         if(daGestalt(gestaltCTBVersion) < 0x0100) {
  38.             StopAlert(256, nil);
  39.             return;
  40.         }
  41.     }
  42.     switch(demoNum) {
  43.         case iDemoTab1:
  44.             d = GetNewDialog(DEMOTAB1, 0L, (DialogPtr)-1);
  45.         break;
  46.         case iDemoTab2:
  47.             d = GetNewDialog(DEMOTAB2, 0L, (DialogPtr)-1);
  48.         break;
  49.         case iDemoTab3:
  50.             d = GetNewDialog(DEMOTAB3, 0L, (DialogPtr)-1);
  51.         break;
  52.         case iDemoTab4:
  53.             d = GetNewDialog(DEMOTAB4, 0L, (DialogPtr)-1);
  54.         break;
  55.     }
  56.     if(d) {
  57.         GetPort(&savePort);
  58.         SetPort(d);    
  59.         
  60.         filterUPP = NewModalFilterProc(tabFilter);
  61.         if(filterUPP == nil)
  62.             return;
  63.             
  64.         toPanel = daGetCtlValue(d, TABCNTL);
  65.     
  66.         panelSwap(d, FIRSTPANEL, currPanel, toPanel, CTLTOKEEP);
  67.         
  68.         currPanel = toPanel;
  69.         
  70.         ShowWindow(d);
  71.                 
  72.         do {
  73.             movableModalDialog(filterUPP,&itemHit);
  74.             
  75.             if(itemHit == TABCNTL) {
  76.                 toPanel = daGetCtlValue(d, TABCNTL);
  77.                 if(toPanel != currPanel) {
  78.                     panelSwap(d, FIRSTPANEL, currPanel, toPanel, CTLTOKEEP);
  79.                     currPanel = toPanel;
  80.                 }
  81.             
  82.             }
  83.         }while(itemHit != ok && itemHit != cancel);
  84.         DisposDialog(d);
  85.         DisposeRoutineDescriptor(filterUPP);
  86.         SetPort(savePort);
  87.     }
  88. }
  89.  
  90. static pascal char    tabFilter    (DialogPtr theDialog, EventRecord *theEvent, 
  91.                                         short *theItem)
  92. {
  93.     char             c, result = FALSE;
  94.     
  95.     switch(theEvent->what) {
  96.         case keyDown:
  97.          case autoKey:
  98.          
  99.              c = theEvent->message & charCodeMask;
  100.              
  101. // check for an exit key, really should put this into movableModal…
  102.  
  103.              result = daExitKey(theDialog, theEvent, theItem, cancel);
  104.              if(result)
  105.                  break;
  106.                  
  107. // check for cmd or cntl TAB to switch panels
  108.                  
  109.             if(theEvent->modifiers & controlKey ||
  110.                 theEvent->modifiers & cmdKey) {
  111.                  result = panelCmdTab(theDialog, TABCNTL, c, theItem);
  112.                  if(result)
  113.                      break;
  114.              }
  115.          break;
  116.      }
  117.      return(result);
  118. }
  119.